<template>
  <div>
    <PageList>
      <template #header>平台设置</template>
      <template #filter>
        <el-form ref="RefForm" :model="formData" label-width="140px" status-icon>
          <el-form-item class="wid" label="平台IP地址">
            <el-input v-model="formData.serverIP" class="wid" placeholder="请输入"></el-input>
          </el-form-item>
          <el-form-item class="wid" label="端口">
            <el-input v-model="formData.serverPort" class="wid" placeholder="请输入"></el-input>
          </el-form-item>
          <el-form-item class="wid" label="当前设备序列号">
            <el-input v-model="formData.serialCode" class="wid" placeholder="请输入"></el-input>
          </el-form-item>
          <el-form-item class="wid">
            <el-button type="primary" :loading="loading" @click="sure">确定</el-button>
          </el-form-item>
        </el-form>
      </template>
    </PageList>
  </div>
</template>
<script>
  import listMixin from '@/mixins/list'
  import { setting } from '@/api/api'
  export default {
    mixins: [listMixin],
    data() {
      return {
        loading: false,
        // 当前设备序列号
        formData: {
          serverIP: '',
          serverPort: '',
          serialCode: ""
        }
      }
    },
    methods: {
      // 获取默认数据
      async getList(query) {
        try {
          const { data } = await setting('get', {}, false)
          this.formData = data
        } catch (err) {
          let er = err
        }
      },
      // 点击确定更新
      async sure() {
        this.loading = true
        try {
          const { data } = await setting('put', { id: this.formData.id, value: this.formData }, false)
          if (data.success == true) {
            this.getList()
            this.$message({
              type: 'success',
              message: '设置成功！'
            })
          }
        } catch (err) {
          this.$message.error('设置失败！')
        }
        this.loading = false
      }
    }
  }
</script>
<style lang="scss" scoped>
  .wid {
    width: 300px;
  }
</style>
